package com.shuai.jit.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shuai.jit.entity.Menu;
import com.shuai.jit.entity.R;
import com.shuai.jit.entity.user.User;
import com.shuai.jit.mapper.MenuMapper;
import com.shuai.jit.mapper.UserMapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api("菜单控制类")
@RequestMapping("/user")
public class MenuController {

    @Autowired
    MenuMapper menuMapper;

    @Autowired
    UserMapper userMapper;

    /**
     * 根据用户等级获取菜单
     * @param id
     * @return
     */
    @RequestMapping("/getMenu")
    public R getMenu(String id){
        User user=userMapper.selectById(id);
        QueryWrapper<Menu> queryWrapper=new QueryWrapper();
        if(user==null){
            // 就是游客
            queryWrapper.le("parentid",0);
            return R.ok().data("menu",menuMapper.selectList(queryWrapper));
        }else {
            queryWrapper.le("parentid",user.getUserLev());

        }
        return R.ok().data("menu",menuMapper.selectList(queryWrapper));
    }
}
